package assignment11;

import java.io.*;
import java.util.zip.*;

public class GZFile {
   public static void main(String[] args) throws IOException {
	   String SourcePath = "G:\\Users\\IOtest\\憨批.txt"; //源文件
	   String DestPath = "G:\\Users\\GZtest\\hp.gz"; //目标文件
	   FileInputStream in = new FileInputStream(SourcePath); 
	   GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(DestPath));
	   //准备将文件内容写入压缩文件
	   System.out.println("Writing compressing file from "+SourcePath+" to "+DestPath);
	   int c;
	   while((c = in.read()) != -1) //判断文件是否读完
		   out.write(c); //写压缩文件    
	   //写完压缩文件后关闭读写流
	   in.close();
	   out.close();
	   //准备将压缩文件中的内容读到显示器
	   System.out.println("Reading file form "+DestPath+" to monitor");
	   BufferedReader in2 = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(DestPath))));
	   String s;
	   while((s = in2.readLine()) != null) //判断是否读完
		   System.out.println(s); //将内容输出到显示器
	   in2.close();
	   String newFilePath = "G:\\Users\\GZtest\\uztest.txt";
	   //准备将压缩文件中的内容写入到新的txt文档中
	   System.out.println("Writing decompression to "+newFilePath);
	   //创建压缩文件流对象
	   GZIPInputStream in3 = new GZIPInputStream(new FileInputStream(DestPath));
	   FileOutputStream out2 = new FileOutputStream(newFilePath);
	   while((c=in3.read())!=-1)
		   out2.write(c);
	   in3.close();
	   out2.close();
   }
}